#ifndef ERROR_HPP
#define ERROR_HPP

#include "trace.hpp"
#include <cstring>

typedef enum
{
        ERROR_NONE                      = 0,
        ERROR_GENERIC                   = -1,
        ERROR_STATE_UNEXPECTED          = -2,
        ERROR_UNSUPPORTED               = -3,
        ERROR_UNIMPLEMENTED             = -4,
        ERROR_INVALID_ARGUMENTS         = -5,
        ERROR_NOT_ENOUGH_MEMORY         = -6,
        ERROR_INVALID_INPUT             = -7,
        ERROR_IO                        = -8,
        ERROR_EDGE_ALREADY_EXISTS       = -9,
        ERROR_INVALID_EDGE              = -10,
        ERROR_UNNORMALIZED_EDGE         = -11,
        ERROR_INVALID_END_CONDITION     = -12,
        ERROR_UNINITIALIZED             = -13,
        ERROR_INVALID_CLOCK_RESOLUTION  = -14,
} error_e;

inline static void on_error ( error_e error_code )
{
        ::trace ( TRACE_LEVEL_HIGH, "Error #%d occured\n", error_code );
        #ifndef RELEASE
                __builtin_trap ();
        #else
                throw error_code;
        #endif 
}

#define throw_if( condition, error_code )               \
        do {                                            \
                if ( condition ) {                      \
                        on_error ( error_code );        \
                }                                       \
        } while ( 0 )

#endif

